
//  NicknameViewController.m
//  Village
//  Created by longrise on 2017/9/21.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "NicknameViewController.h"

@interface NicknameViewController ()
@property (nonatomic ,strong)UITextField *text;
@end

@implementation NicknameViewController
//- (void)setParams:(id)obj block:(LongriseRouterBlock)block
//{
//    self.routerBlock = block;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = kBackgroundColor;
    self.title = @"设置昵称";
    
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedOKbtn)];
    [rightBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                          [UIFont systemFontOfSize:15], NSFontAttributeName,
                                          [UIColor whiteColor], NSForegroundColorAttributeName,
                                          nil]
                                forState:UIControlStateNormal];
    
    [rightBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                          [UIFont systemFontOfSize:15], NSFontAttributeName,
                                          [UIColor whiteColor], NSForegroundColorAttributeName,
                                          nil]
                                forState:UIControlStateHighlighted];
    
    self.navigationItem.rightBarButtonItem = rightBarItem;

    
    
    _text = [[UITextField alloc] initWithFrame:CGRectMake(0, 10*kScreenScaleY, kDeviceWidth, 50*kScreenScaleY)];
    _text.backgroundColor = [UIColor whiteColor];
    _text.placeholder = @"请输入昵称";
    _text.borderStyle = UITextBorderStyleRoundedRect;
    _text.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.view addSubview:_text];
}

- (void)onClickedOKbtn{
     WeakSelf(weakSelf);
    if (_text.text.length){
        
        NSMutableDictionary *bean = [NSMutableDictionary dictionary];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [bean setValue:dict forKey:@"entitybean"];
        [dict setObject:[Globle getInstance].account.userid forKey:@"id"];
        [dict setObject:_text.text forKey:@"nickname"];
        
        [NetRequestClass Post:UpdateUserInfoURL Parameters:bean success:^(id result) {
            [MBProgressHUD hideHUDForView:weakSelf.navigationController.view];
            [MBProgressHUD showSuccess:result[@"message"] toView:weakSelf.navigationController.view Completion:^{
                [[Globle getInstance] saveAccountInfo:result[@"data"]];
                [self.navigationController popViewControllerAnimated:YES];
            }];
            
        } failure:^(id valueCode, id error) {
            [MBProgressHUD hideHUDForView:weakSelf.navigationController.view];
        }];
        
    }else{
       [MBProgressHUD showError:@"昵称不能为空" toView:self.navigationController.view];
    }
   
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
